import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/Index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/', name: 'index', component: Index,
    children: [
      { path: '/Users', name: 'Users', component: () => import('../views/系统设置/用户管理/Sel.vue') },
      { path: '/PersonalData', name: 'PersonalData', component: () => import('../views/系统设置/个人信息/PersonalData.vue') },
      { path: '/Goods', name: 'Goods', component: () => import('../views/信息管理/商品管理/Index.vue')},
      { path: '/order', name: 'order', component: () => import('../views/信息管理/订单管理/Index.vue')},
      { path: '/SStore', name: 'SStore', component: () => import('../views/信息管理/店铺信息/Index.vue')},
      { path: '/Members', name: 'Members', component: () => import('../views/信息管理/会员管理/Index.vue')},
      { path: '/Menu', name: 'Menu', component: () => import('../views/系统设置/菜单设置/Menu.vue')},
      { path: '/DDHT', name: 'DDHT', component: () => import('../views/控制台/后台点单/Index.vue')},


      { path: '/MemberReport', name: 'MemberReport', component: () => import('../views/数据报表/会员报表/MemberReport.vue')},
      { path: '/OS', name: 'OS', component: () => import('../views/系统设置/组织架构/Index.vue'),children:[
        { path: '/OS/Role', name: 'Role', component: () => import('../views/系统设置/组织架构/角色管理/Index.vue')},
        { path: '/OS/Dept', name: 'Dept', component: () => import('../views/系统设置/组织架构/部门管理/Index.vue')},
      ]},
      { path: '/SalesReport', name: 'SalesReport', component: () => import('../views/数据报表/销售报表/Index.vue')},
    ]
  },
  { path: '/login', name: 'login', component: () => import('../views/Login.vue') }
]

//实例 路由对象
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//路由导航守卫 
router.beforeEach((to, from, next) => {
  //修改自定义标题
  document.title=to.meta.title;
  //登录验证
  if(sessionStorage.getItem('token')==null&&to.path!='/login'){
    router.push('/login');
  }else{
    //放行
    next();
  } 
})



export default router
